<template>
  <star-table
    :ref="ref"
    :config="config"
    :loading="loading"
    :data="data"
    :columns="columns"
    :additionalAction="additionalAction"
    :pageSizeOpts="pageSizeOpts"
    :pageNavigation="pageNavigation"
    :queryFormItem="queryFormItem"
    :collapseFormItem="collapseFormItem"
    :btnShowFun="btnShowFun"
    :rowbgc="rowbgc"
    :tableStyle="{ overflow: 'hidden !important' }"
    @loadPage="loadPage"
    @handleEdit="handleEdit"
    @handleDelete="handleDelete"
    @handleDetail="handleDetail"
    @handleClick="handleClick"
    @handleDbClick="handleDbClick"
    @handleCreate="handleCreate"
    @handleDeleteMultiple="handleDeleteMultiple"
    @handleSearch="handleSearch"
    @handleReset="handleReset"
  ></star-table>
</template>

<script>
const ref = "mainTable";
export default {
  name: ref,
  components: {},
  inject: ["anc"],
  data() {
    return {
      ref: "mainTable",
      loading: false,
      pageNavigation: {
        total: 0,
        pageSize: 10,
        pageNumber: 1,
      },
      equipTypeOptions: [],
    };
  },
  props: {
    data: {
      default: () => {
        return [];
      },
    },
  },
  watch: {},
  computed: {
    config() {
      return {
        search: true,
        addButton: true,
        batchDeleteButton: false,
        downloadIcon: true,
        uploadIcon: false,
        uploadUrl: "/",
        tableSizeIcon: false,
        fullscreenIcon: false,
        refreshIcon: true,
        columnSettingIcon: true,
        checkColumnDisabled: true,
        action: false, // 操作
        additionalAction: true, // 新增自定义
      };
    },
    columns() {
      return [
        {
          key: "batchNo",
          title: "批次号",
          minWidth: 200,
          align: "center",
          show: true,
        },
        {
          key: "tankNo",
          title: "桶号",
          minWidth: 200,
          align: "center",
          show: true,
        },
        {
          key: "productId",
          title: "规格ID",
          minWidth: 100,
          align: "center",
          show: true,
          render: (h, params) => {
            return h(
              "div",
              {},
              this.getOptionValue(this.anc.productOptions, params.row.productId)
            );
          },
        },
        {
          key: "status",
          title: "状态",
          minWidth: 100,
          align: "center",
          show: true,
        },
        {
          key: "weight",
          title: "重量(KG)",
          minWidth: 100,
          align: "center",
          show: true,
        },
        // {
        //   key: "usedCapacity",
        //   title: "已用重量(KG)",
        //   minWidth: 100,
        //   align: "center",
        //   show: true,
        // },
        // {
        //   key: "restCapacity",
        //   title: "剩余重量(KG)",
        //   minWidth: 100,
        //   align: "center",
        //   show: true,
        // },
        {
          key: "qualityResult",
          title: "质检结果",
          minWidth: 100,
          align: "center",
          show: true,
        },
        {
          key: "fsssGrind",
          title: "研磨fsss",
          minWidth: 100,
          align: "center",
          show: true,
        },
        {
          key: "fsssOriginal",
          title: "原态fsss",
          minWidth: 100,
          align: "center",
          show: true,
        },
        {
          key: "ctValue",
          title: "ct值",
          minWidth: 100,
          align: "center",
          show: true,
        },
        {
          key: "storehouseId",
          title: "仓库Id",
          minWidth: 100,
          align: "center",
          show: true,
        },
        {
          key: "locationId",
          title: "库位Id",
          minWidth: 100,
          align: "center",
          show: true,
        },
      ];
    },
    additionalAction() {
      return {
        key: "additionalAction",
        title: "操作",
        slot: "additionalAction",
        width: 200,
        fixed: "right",
        align: "center",
        minWidth: 100,
        show: true,
        show: true,
        buttons: [
          {
            title: "提交报工单",
            style: (row, column, index, item, i) => {
              if (!!row.status) {
                return {
                  "pointer-events": "none",
                  color: "gray",
                };
              }
            },
            event: (row, index) => this.anc.submitWorkReportRecord(row),
          },
          {
            title: "编辑",
            style: (row, column, index, item, i) => {
              if (!!row.status) {
                return {
                  "pointer-events": "none",
                  color: "gray",
                };
              }
            },
            event: (row, index) => this.anc.handleEdit(row, index),
          },
          {
            title: "删除",
            style: (row, column, index, item, i) => {
              if (!!row.status) {
                return {
                  "pointer-events": "none",
                  color: "gray",
                };
              }
            },
            event: (row, index) => this.anc.handleDelete(row, index),
          },
          { title: "查看", event: (row, index) => this.anc.handleDetail(row) },
        ],
      };
    },
    pageSizeOpts() {
      return [10, 30, 50, 100];
    },
    // pageNavigation() {
    //   return { total: 0, pageSize: 10, pageNumber: 1 };
    // },
    queryFormItem() {
      return [];
    },
    collapseFormItem() {
      return [];
    },

    btnShowFun() {
      return function () {
        return true;
      };
    },
    rowbgc() {
      return "red";
    },
  },
  created() {},
  mounted() {
    this.$nextTick(() => {
      this.$set(this.anc.vms, this.ref, this);
      this.loadPage(this.pageNavigation, {});
    });
  },
  methods: {
    loadPage(pageNavigation, filter, orderBy = {}) {
      //   //删除查询项中属性值为空的查询条件
      this.anc.loadPage(pageNavigation, filter, orderBy);
    },
    handleEdit(row, index) {
      console.log(row, index);
      this.anc.handleEdit(row, index);
    },
    handleDelete(row, index) {
      this.anc.handleDelete(row, index);
    },
    handleDetail(row, index) {
      this.anc.handleDetail(row);
    },
    handleClick(row, index) {},
    handleDbClick(row, index) {},
    handleDeleteMultiple(selection) {
      this.anc.handleDeleteMultiple(selection);
    },
    handleSearch(filter) {
      this.pageNavigation.pageNumber = 1;
      this.loadPage(this.pageNavigation, filter, this.orderBy);
    },
    handleReset() {
      this.pageNavigation.pageNumber = 1;
      this.loadPage(this.pageNavigation, null, this.orderBy);
    },
    handleCreate() {
      this.anc.handleCreate();
    },
    getOptionValue(options, value, key = "label") {
      let dataValue = "";
      let index = options.findIndex((d) => d.value === value);
      if (index !== -1) {
        dataValue = options[index][key];
      }
      return dataValue;
    },
  },
};
</script>
<style scoped></style>
